<?php

namespace Home\Controller;
use OT\DataDictionary;

header('content-type:text/html;charset=utf8');

class ProductController extends HomeController {
    public function index(){
        $id = I('get.id');
        $shop = D('shop')->where(array('id'=>$id))->find();
        //$shop = D('shop')->join("onethink_price on onethink_shop.id=onethink_price.sid")->find();
        //dump($shop);
        
        
        // $cate = get_parent_category($shop['fid']);
        // var_dump($cate);
        
        //查询属性类别
        $attr = D("attr")->where(array('sid'=>$id))->select();
        $value = D("value")->where(array('sid'=>$id))->select();

        foreach ($attr as &$v) {
            foreach ($value as $vv) {
                if($v['id'] == $vv['kid']){
                    $v['val'][] = $vv;
                }
            }
        }
        $p = D('shop')->join("onethink_price on onethink_shop.id=onethink_price.sid")->where(array('sid'=>$id))->find();
        /*第二种查询
        $p = D('shop')->join("onethink_price on onethink_shop.id=onethink_price.sid where onethink_price.sid=$id")->select();*/
        //dump(D('shop')->getLastSql());
        //dump($p);
        $img = $p['img'];
        //dump($img);
        $img = explode(',',$img);
        //dump($attr[0]['val']);
        dump($img);
        //dump($attr[0]);
       // dump($value);
        //dump(D('attr')->getLastSql());
        $this->assign('shop',$shop);
        $this->assign('attr',$attr);
        $this->assign('img',$img);
        $this->assign('value',$value);
        $this->display();
    }

    public function price(){
        $where['sid'] = I('post.sid');
        $where['vid'] = implode(',',I('post.attrvid'));
        $res = D('price')->where($where)->find();
      
        if($res){
            $return['data'] = $res['price'];
            $return['status'] = 1;
            $return['info'] = 'success';
        }else{
            $return['data'] = null;
            $return['status'] = 0;
            $return['info'] = 'error';
        }
        $return=$this->ajaxReturn($return);
    }



}